*******************Institution Paper*****Fall 2023*******************
*******************Research Question: Thow the trust in political institutions shapes political participation in less democratic countries?****
*******************DV: Political Participation******************* 
*******************IV: Trust in Political Institution*******************


*To Upload the data
use "/Users/daniaarayssi/Desktop/CU Boulder PhD Program Material/Courses/Fall 2023/Institutions/Paper Project/Data /mydata2.dta", clear 

*******************I need to drop every country except Tunisian Algeria Lebanon Iraq and Egyp*******************
drop if country == 8
drop if country == 15
drop if country == 17
drop if country == 19
drop if country == 22

keep country q5022 t904 t902 eg802 eg805 q301 q13 q2012 q2011 q2012  q2014 q2015 q2016 q2017 q1002 q1004 q1008 q5011 te501a q1001 q1003 t1003 q1014 

********************************************CLEADING, AND RECODING VARIABLES******************************** 

*******************************************INDEPENDENT VARIABLES: PROTEST AND VOTING TURNOUT******
**********************************************PROTEST********************************

************TUNISIA**********
******Internet****
generate protestinternet_tunisia =. 
replace protestinternet_tunisia = 1 if t904 == 1
replace protestinternet_tunisia = 0 if t904 == 2
label define protestinternet_tunisia ///
1 "Yes" ///
0 "No", replace 
label values protestinternet_tunisia protestinternet_tunisia
label variable protestinternet_tunisia "Did you participate in protests through the internet?"

*****Physical****
generate protestphysical_tunisia =. 
replace protestphysical_tunisia = 1 if t902 == 1
replace protestphysical_tunisia = 0 if t902 == 2
label define protestphysical_tunisia ///
1 "Yes" ///
0 "No", replace 
label values protestphysical_tunisia protestphysical_tunisia
label variable protestphysical_tunisia"Did you participate in the protests against former president Ben Ali between December 17th, 2010 and January 14th, 2011?"


************Egypt**********
******Internet****
generate protestinternet_egypt =. 
replace protestinternet_egypt = 1 if eg805 == 1
replace protestinternet_egypt = 0 if eg805 == 2
label define protestinternet_egypt ///
1 "Yes" ///
0 "No", replace 
label values protestinternet_egypt protestinternet_egypt
label variable protestinternet_egypt "Did You Participate in protests through the internet?"

*****Physical****
generate protestphysical_egypt =. 
replace protestphysical_egypt = 1 if eg802 == 1
replace protestphysical_egypt = 0 if eg802 == 2
label define protestphysical_egypt ///
1 "Yes"  ///
0 "No", replace 
label values protestphysical_egypt protestphysical_egypt
label variable protestphysical_egypt "Did you participate in the protests against Hosni Mubarak ? "




************ALGERIA, LEBANON, IRAQ **********
rename q5022 Political_Activities_Protest
label variable Political_Activities_Protest   "During the past three years, did you participate in a protest, march or sit-in?"
recode Political_Activities_Protest 8=. 9=. 
generate Protest_Activities=Political_Activities_Protest
recode Protest_Activities(1=1) (2=1)
recode Protest_Activities(3=0) 
label variable Protest_Activities  "During the past three years, did you participate in a protest, march or sit-in?"
label define Protest_Activities ///
1 "Yes" ///
0 "No", replace 
label values Protest_Activities Protest_Activities


*********** First DV: Protest for five countries *****
generate protest =. 
replace protest = 1 if protestphysical_egypt == 1
replace protest = 0 if protestphysical_egypt == 0
replace protest = 1 if protestphysical_tunisia == 1 
replace protest = 0 if protestphysical_tunisia == 0
replace protest = 1 if Protest_Activities == 1 
replace protest = 0 if Protest_Activities == 0
label define protest ///
1 "Yes" ///
0 "No", replace 
label values protest protest
label variable protest  "During the past three years, did you participate in a protest, march or sit-in?"

*********** Second DV: Voting turnout*****TUNISIA, ALGERIA, LEBANON, IRAQ, EGYPT**********
generate vote =. 
replace vote = 1 if q301 == 1
replace vote = 0 if q301 == 2
label define vote ///
1 "Yes" ///
0 "No", replace 
label values vote vote
label variable vote "Did you vote in the last parliamentary elections?"



*******************************************INDEPENDENT VARIABLES: TRUST IN GOVERNMENT INSTITUTIONS***********
************All these independent variables were asked across these five countries. 
****Treating some categories as missing**** 
recode q2011 0=. 8=. 9=. 
recode q2012 0=. 8=. 9=. 
recode q2014 0=. 8=. 9=. 
recode q2015 0=. 8=. 9=. 
recode q2016 0=. 8=. 9=. 
recode q2017 0=. 8=. 9=. 


******recoding the order of the categories**** 
******TRUST IN GOVERNMENT****
generate government_trust=.
replace government_trust= 1 if q2011==4
replace government_trust= 2 if q2011==3
replace government_trust= 3 if q2011==2
replace government_trust= 4 if q2011==1
label variable government_trust "How much do you trust the government?"
label define government_trust ///
1 "I absolutely do not trust it" ///
2 "I trust it to a limited extent " ///
3 "I trust it to a medium extent" ///
4 "I trust it to a great extent" , replace 
label values government_trust government_trust 

******TRUST IN JUDICIARY****
generate judiciary_trust=.
replace judiciary_trust= 1 if q2012==4
replace judiciary_trust= 2 if q2012==3
replace judiciary_trust= 3 if q2012==2
replace judiciary_trust= 4 if q2012==1
label variable judiciary_trust "How much do you trust the judiciary?"
label define judiciary_trust ///
1 "I absolutely do not trust it" ///
2 "I trust it to a limited extent " ///
3 "I trust it to a medium extent" ///
4 "I trust it to a great extent" , replace 
label values judiciary_trust judiciary_trust 

******TRUST IN POLICE****
generate police_trust=.
replace police_trust= 1 if q2014==4
replace police_trust= 2 if q2014==3
replace police_trust= 3 if q2014==2
replace police_trust= 4 if q2014==1
label variable police_trust "How much do you trust the police?"
label define police_trust ///
1 "I absolutely do not trust it" ///
2 "I trust it to a limited extent " ///
3 "I trust it to a medium extent" ///
4 "I trust it to a great extent" , replace 
label values police_trust police_trust

******TRUST IN POLITICAL PARTIES****
generate parties_trust=.
replace parties_trust= 1 if q2015==4
replace parties_trust= 2 if q2015==3
replace parties_trust= 3 if q2015==2
replace parties_trust= 4 if q2015==1
label variable parties_trust "How much do you trust the political parties?"
label define parties_trust ///
1 "I absolutely do not trust it" ///
2 "I trust it to a limited extent " ///
3 "I trust it to a medium extent" ///
4 "I trust it to a great extent" , replace 
label values parties_trust parties_trust

******TRUST IN ARMED FORCES****
generate armedforces_trust=.
replace armedforces_trust= 1 if q2016==4
replace armedforces_trust= 2 if q2016==3
replace armedforces_trust= 3 if q2016==2
replace armedforces_trust= 4 if q2016==1
label variable armedforces_trust "How much do you trust the armed forces?"
label define armedforces_trust ///
1 "I absolutely do not trust it" ///
2 "I trust it to a limited extent " ///
3 "I trust it to a medium extent" ///
4 "I trust it to a great extent" , replace 
label values armedforces_trust armedforces_trust

******TRUST IN CIVIL SOCIETY****
generate civilsociety_trust=.
replace civilsociety_trust= 1 if q2017==4
replace civilsociety_trust= 2 if q2017==3
replace civilsociety_trust= 3 if q2017==2
replace civilsociety_trust= 4 if q2017==1
label variable civilsociety_trust "How much do you trust civil society institutions?"
label define civilsociety_trust ///
1 "I absolutely do not trust it" ///
2 "I trust it to a limited extent " ///
3 "I trust it to a medium extent" ///
4 "I trust it to a great extent" , replace 
label values civilsociety_trust civilsociety_trust


*************************************CONTROL VARIABLES*******************
generate gender=. 
replace gender = 1 if q1002==1 
replace gender = 2 if q1002==2 
label variable gender "what is your gender?"
label define gender ///
1 "male" ///
2 "female"  , replace 
label values gender gender

generate work_status=. 
replace work_status = 1 if q1004==1 
replace work_status = 0 if q1004==2 
label variable work_status "do you work?"
label define work_status ///
1 "yes" ///
0 "no"  , replace 
label values work_status work_status

generate employment_sector=. 
replace employment_sector = 1 if q1008==1 
replace employment_sector = 2 if q1008==2 
replace employment_sector = 3 if q1008==3 
label variable employment_sector "which sector do you work?"
label define employment_sector ///
1 "public" ///
2 "private" ///
3 "other"  , replace 
label values employment_sector employment_sector


generate urban_rural=. 
replace urban_rural = 1 if q13==1 
replace urban_rural = 2 if q13==2  
label variable urban_rural "urban or rural area"
label define urban_rural ///
1 "urban" ///
2 "rural"  , replace 
label values urban_rural urban_rural

******mMEMBERHSIP IN A POLITICAL PARTY*****
generate membership_party=. 
replace membership_party = 1 if q5011==1 
replace membership_party = 0 if q5011==2 
replace membership_party = 1 if te501a==1 
replace membership_party = 0 if te501a==2 
label variable membership_party "are you a member of a political party "
label define membership_party ///
1 "yes" ///
0 "no" , replace 
label values membership_party membership_party

****age***
rename q1001 age 

***Education****
generate education=. 
replace education = 1 if t1003 == 1
replace education = 1 if q1003 == 1
replace education = 2 if q1003 == 2 
replace education = 2 if t1003 == 2
replace education = 3 if q1003 == 3 
replace education = 3 if t1003 == 3
replace education = 4 if q1003 == 4 
replace education = 4 if t1003 == 4
replace education = 6 if q1003 == 5
replace education = 5 if q1003 == 6
replace education = 5 if t1003 == 5
replace education = 7 if q1003 == 7 
replace education = 7 if t1003 == 6  
label define education ///
1 "illiterate/literate" ///
2 "elementary" ///
3 "preparatory/basic" ///
4 "secondary" ///
5 "ba" ///
6 "mid-level diploma" ///
7 "ma and above" , replace 
label values education education


******************************************Standarlized Variables*******************
egen armedforces = std( armedforces_trust)
egen civilsociety = std(civilsociety_trust) 
label values civilsociety civilsociety
egen government = std(government_trust)
egen police = std(police_trust)
egen politicalparties = std(parties_trust)
egen judiciary = std(judiciary_trust)
egen genderidentity = std(gender)
egen rural_urban = std(urban_rural)
egen Age = std(age)
egen member_party = std(membership_party)
egen workstatus = std(work_status)
egen Education = std(education)
egen protests = std(protest)
egen voting = std(vote)

*************************************************MODELS******************************************

********How the variation in trust in each political institutions affect protest**** 
logit protests armedforces genderidentity rural_urban Age member_party workstatus Education
logit protests civilsociety  genderidentity rural_urban Age member_party workstatus Education 
logit protests government  genderidentity rural_urban Age member_party workstatus Education
logit protests  politicalparties  genderidentity rural_urban Age member_party workstatus Education 
logit protests  judiciary genderidentity rural_urban Age member_party workstatus Education 

logit voting armedforces genderidentity rural_urban Age member_party workstatus Education
logit voting civilsociety  genderidentity rural_urban Age member_party workstatus Education 
logit voting government  genderidentity rural_urban Age member_party workstatus Education
logit voting  politicalparties  genderidentity rural_urban Age member_party workstatus Education 
logit voting  judiciary genderidentity rural_urban Age member_party workstatus Education 

logit protest armedforces civilsociety government police politicalparties judiciary genderidentity rural_urban Age member_party workstatus Education i.country

outreg2 using logit_1_v2.doc, replace ctitle (Model 1) label addtext(Country FE, YES)
outreg2 using logit_1_v2.doc, append ctitle(Odds ratio) eform
coefplot, xline(0)


margins, at(civilsociety=(1  4)) predict(pr) atmeans
marginsplot,legend(size(*0.5)label(1 "Not trust it")label(4 "trust it to a great extent"))

margins, at(police=(1  4)) predict(pr) atmeans
marginsplot,legend(size(*0.5)label(1 "Not trust it")label(4 "trust it to a great extent"))

margins, at(government=(1  4)) predict(pr) atmeans
marginsplot,legend(size(*0.5)label(1 "Not trust it")label(4 "trust it to a great extent"))

margins, at(judiciary=(1  4)) predict(pr) atmeans
marginsplot,legend(size(*0.5)label(1 "Not trust it")label(4 "trust it to a great extent"))



********How the variation in trust in each olitical institutions affect voting turnout**** 
logit vote armedforces_trust civilsociety_trust government_trust police_trust parties_trust judiciary_trust gender urban_rural age membership_party work_status education 


logit vote armedforces civilsociety government police politicalparties judiciary genderidentity rural_urban Age member_party workstatus Education i.country

outreg2 using logit_2_v2.doc, replace ctitle (Model 2) label addtext(Country FE, YES)
outreg2 using logit_2_v2.doc, append ctitle(Odds ratio) eform
coefplot, xline(0)

margins, at(government_trust=(1  4)) predict(pr) atmeans
marginsplot,legend(size(*0.5)label(1 "Not trust it")label(4 "trust it to a great extent"))

margins, at(judiciary_trust=(1  4)) predict(pr) atmeans
marginsplot,legend(size(*0.5)label(1 "Not trust it")label(4 "trust it to a great extent"))



